<template>
  <div id="app">
    <h1>JSON to Table Editor</h1>
    <div class="container">
      <div class="json-preview">
        <h3>当前 JSON 数据：</h3>
        <pre>{{ JSON.stringify(jsonData, null, 2) }}</pre>
      </div>
      <JsonToTable :data="jsonData" @save="handleSave" />
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import JsonToTable from './components/JsonToTable.vue';

// 测试数据 - 数组形式
const jsonData = ref([
  {
    "班": "1班",
    "人数": 34,
    "老师": {
      "姓名": "张老师",
      "年龄": 30

    }
  }, {
    "班": "1班",
    "人数": 34,
    "老师": {
      "姓名": "张1老师",
      "年龄": 31
    }
  }]);

const handleSave = (updatedData) => {
  console.log('Updated JSON data:', updatedData);
  jsonData.value = updatedData;
};
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
  margin-top: 60px;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

h1 {
  text-align: center;
  margin-bottom: 40px;
}

.json-preview {
  margin-bottom: 20px;
  padding: 20px;
  background-color: #f8f9fa;
  border-radius: 4px;
}

.json-preview h3 {
  margin-top: 0;
  margin-bottom: 10px;
}

pre {
  margin: 0;
  padding: 10px;
  background-color: #f1f1f1;
  border-radius: 4px;
  overflow-x: auto;
}
</style>